/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */

import  org.jdom.JDOMException;
import  org.jdom.input.SAXBuilder;
import  java.io.IOException;
import  org.jdom.*;
import  java.util.*;

public class XMLParser {
    
    public static ArrayList<String> parser(Document doctemp){

        Hashtable<String, Integer> algoritms = new Hashtable();
        Hashtable<Integer, String> atributes = new Hashtable();
        ArrayList<String> tempArray = new ArrayList();
        SAXBuilder builder = new SAXBuilder();
        Document doc = doctemp;
        Element root = doc.getRootElement();
        Element child = root.getChild("scheduling");
        List<Element> children = child.getChildren();
        LinkedList<String> fields = new LinkedList<String>();

        algoritms.put("FCFS", 1);
        algoritms.put("SJF", 2);
        algoritms.put("PRIORITY", 3);

        atributes.put(0, "id");
        atributes.put(1, "name");
        atributes.put(2, "type");
        atributes.put(3, "quantum");
        atributes.put(4, "preemptive");
        atributes.put(5, "queueOnQuantumEnd");
        atributes.put(6, "queueOnIOEnd");

        //if(options_table.containsKey(root.getName()))
        //    tipo = options_table.get(root.getName());
        String parseString;
        tempArray.add(child.getAttributeValue("startQueue"));
        for(int i = 0; i < children.size(); i++){
            parseString = "";
            for(int j = 0; j < 7; j++){
                if(j == 2)
                    parseString = parseString + algoritms.get(children.get(i).getAttributeValue(atributes.get(j)).toUpperCase()) + " ";
                else
                    parseString = parseString + children.get(i).getAttributeValue(atributes.get(j)) + " ";
            }
            tempArray.add(parseString);
        }
        return(tempArray);
    }
}